<?
define('BASEPATH', true);
require_once('../inc/config.php');
if(!$is_online){exit;}

if(isset($_GET['id'])){
$uid = $db->EscapeString($_GET['id']);

	if($_GET['step'] == "skip"){
		$db->Query("INSERT INTO `followed` (user_id, site_id) VALUES('".$data['id']."', '".$uid."')");
		echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Done!</b></font></td></tr></table>';
	}else{
		$tname = $db->FetchArray($db->Query("SELECT t_name FROM `twitter` WHERE `user`='".$data['id']."'"));
		$site = $db->FetchArray($db->Query("SELECT t_name,cpc FROM `twitter` WHERE `id`='".$uid."'"));

		$url  = "http://api.twitter.com/1/friendships/exists.json?screen_name_a=" . $tname['t_name'] . "&screen_name_b=".$site['t_name'];
		$page = get_data($url);
		$sql = $db->Query("SELECT id FROM `followed` WHERE `site_id`='".$uid."' AND `user_id`='".$data['id']."'");
		$plused  = $db->GetNumRows($sql);
		
		if ($page == FALSE) { 
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Error!</b></font></td></tr><tr><td><center><b>We can\'t verify followers!</b></center></td></tr></table>';
		}else if($plused > 0){
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Error!</b></font></td></tr><tr><td><center><b>You already followed @'.$site['t_name'].'!</b></center></td></tr></table>';
		}else if (strpos($page, "true") !== FALSE) {
			$db->Query("UPDATE `users` SET `coins`=`coins`+'".$site['cpc']."' WHERE `id`='".$data['id']."'");
			$db->Query("UPDATE `twitter` SET `earned`=`earned`+'1', `points`=`points`-'".$site['cpc']."' WHERE `id`='".$uid."'");
			$db->Query("INSERT INTO `followed` (user_id, site_id) VALUES('".$data['id']."', '".$uid."')");
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="mainfocus"><tr><td align="center"><font size="3"><b>Success!</b></font></td></tr><tr><td><center><b>You followed @'.$site['t_name'].'!<br><font color="#d4a1ff" size="3">You got '.$site['cpc'].' Coin!</font></center></td></tr></table>';
		}else{
			echo '<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td><center><b>Twitter says you aren\'t following @'.$site['t_name'].'!</b><br><i>Check again if you are logged into ' . $tname['t_name'] . ' on Twitter.</i><br><b>Try Confirming again or Skip them!</b></center></td></tr></table><br>';
		}
	}
}
?>